<?php
/**
 * Class implementing the
 * <a href="http://www.martinfowler.com/eaaCatalog/tableDataGateway.html">Table Data Gateway pattern</a>
 * to access admin table
 */
class CarouselItemTable extends BaseTable
{
    protected $_name = 'carousel_item';

    /**
     * Return the available items of the day
     * @param string $itemType The type of item, this could be 'discount' or 'store_picture'
     * @return array The available items of the day
     */
    public function getAvailableItem($itemType = "discount")
    {
        if (! in_array($itemType, array('discount', 'store_picture'))) {
            throw new Exception('The type of item must be "discount" or "store_picture"');
        }

        $request = $this->select()
            ->from($this->_name)
            ->where("item_type = ?", $itemType)
            ->where("NOW() BETWEEN date_in AND date_out");

        return $this->fetchAll($request)->toArray();
    }

    /**
     * Return all the discounts
     * @return array All the discounts
     */
    public function getAllDiscounts()
    {
        $request = $this->select()
            ->from($this->_name)
            ->where("item_type = 'discount'");

        return $this->fetchAll($request)->toArray();
    }

    /**
     * Return all store pictures
     * @return array All store pictures
     */
    public function getAllStorePictures()
    {
        $request = $this->select()
            ->from($this->_name)
            ->where("item_type = 'store_picture'");

        return $this->fetchAll($request)->toArray();
    }
}